package ru.hh.school;

import ru.hh.school.logging.Logger;
import ru.hh.school.logging.SimpleLogger;
import ru.hh.school.logging.ThreadLogger;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;

public class ServerApp {
    public static void main(String[] args) {
        ServerSocket listenSocket;
        try {
            listenSocket = new ServerSocket(12345, 10);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }

        HashSet<String> roomNames = new HashSet<String>();
        roomNames.add("regular");
        RoomManager roomManager = new RoomManager(roomNames);

        UserManager userManager = new UserManager();
        Logger logger = new ThreadLogger(1000, new SimpleLogger());
        ChatRouter chatRouter = new ChatRouter(roomManager, userManager, logger);
        while (!Thread.interrupted()) {
            Socket socket;
            try {
                socket = listenSocket.accept();
                new User(socket, chatRouter, roomManager.getDefaultRoom());
            } catch (IOException e) {
                // I'm afraid of stacktraces
                // e.printStackTrace();
            }
        }
    }
}
